Musical Instrument assignment

Musical Instrument Assignment

Q1

  1. My musical instrument is controlled by three switches (buttons) that each play a similar but different tune
  2. The player can choose which of the three buttons to press and put together a series of sounds forming a tune
  3. Three diffent notes can be played separately or at the same time
  4. Out of all of the note the lowest the notes can go is 280 and the highest is 200 so the notes are drastically different
  5. each note lasts for 30 milliseconds
  6. It is completely the users choice to make the instrument opperate

My Code

Here's the code I wrote to make the arduino circuit work:

		
/*Musical Instrument Assignment
2017-05-25 to 2017-06-01
Lucca*/

//Variables

  int switch1 = 2;
  int switch2 = 3;
  int switch3 = 4;
  int speaker = 9;

void setup() {

  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
  pinMode(switch3, INPUT);
}

void loop() {
  
  // Calls

    tune1();
    tune2();
    tune3();
}

void tune1 () {

    if (digitalRead(switch1)==HIGH) {
    tone(speaker, 200, 30);
    delay(30);
    } 
}

void tune2 () {

    if (digitalRead(switch2)==HIGH) {
    tone(speaker, 240, 30);
    delay(30);
    }
} 

void tune3 () {

    if (digitalRead(switch3)==HIGH) {
    tone(speaker, 280, 30);
    delay(30);
    } 
}